package com.lagou.demo03.servlet;

import com.lagou.demo03.model.Student;
import com.lagou.demo03.service.StudentUpdateService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "StudentUpdateServlet",urlPatterns = "/studentUpdate")
public class StudentUpdateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取请求中的学生的信息
        String id = request.getParameter("uid");
        System.out.println(id);
        String cls = request.getParameter("ucls");
        System.out.println(cls);
        String name = request.getParameter("uname");
        System.out.println(name);
        String sex = request.getParameter("usex");
        System.out.println(sex);
        String birthday = request.getParameter("ubirthday");
        System.out.println(birthday);
        String mail = request.getParameter("umail");
        System.out.println(mail);
        String note = request.getParameter("unote");
        System.out.println(note);
        String updateId = request.getParameter("updateId");
        System.out.println(updateId);
        //创建StudentService类型的对象，实现数据的插入
        StudentUpdateService studentUpdateService = new StudentUpdateService();
        Student student = studentUpdateService.studentUpdateService(new Student(id, cls, name,sex,birthday,mail,note),updateId);
        //实现客户端跳转
        response.sendRedirect("student.jsp");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
